package com.zj.HJ;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HJ71 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String expre = sc.nextLine();
        String words = sc.nextLine();

        System.out.println(getRes(expre, words));

    }
//te?t*.*    txt12.xls

    public static boolean getRes(String expre, String word) {
        word = word.toLowerCase();
        expre = expre.toLowerCase();
        if (expre.indexOf("*") == -1 && expre.indexOf("?") == -1) {
            return word.equals(expre);
        }
        int i = 0, j = 0;
        for (; i < word.length(); i++) {
            if (j < expre.length() && expre.charAt(j) == word.charAt(i)) {
                j++;
            } else if (!Character.isLetter(word.charAt(i)) && !Character.isDigit(word.charAt(i))) {
                return false;
            } else if (j < expre.length() && expre.charAt(j) == '?') {
                j++;
            } else if (j < expre.length() && expre.charAt(j) == '*') {
                List<Integer> ls1 = getNextK(expre, j, false, '*');
                if (ls1.isEmpty()) {
                    continue;
                } else if (ls1.size() > word.length() - i) {
                    return false;
                } else {
                    int index = ls1.get(0);
                    j = index;

                    List<Integer> nextK = getNextK(word, i, true, expre.charAt(index));
                    for (int k = 0; k < nextK.size(); k++) {
                        char temp = word.charAt(nextK.get(k));
                        if (!Character.isDigit(temp) && !Character.isLetter(temp) && temp != expre.charAt(index)) {
                            return false;
                        } else {
                            i = nextK.get(k);
                            if (getRes(expre.substring(j), word.substring(i))) {
                                return true;
                            }
                        }
                    }
                    return false;
                }

            } else {
                return false;
            }
        }
        return j >= expre.length() - 1 ? true : false;
    }

    public static List<Integer> getNextK(String expre, int index, boolean equal, char ch) {
        List<Integer> res = new ArrayList<>();
        for (int i = index; i < expre.length(); i++) {
            char temp = expre.charAt(i);
            if (equal) {
                if (temp == ch) {
                    res.add(i);
                } else if (!Character.isDigit(temp) && !Character.isLetter(temp)) {
                    res.add(i);
                } else if (ch == '?') {
                    res.add(i);
                }
            } else if (!equal) {
                if (temp != ch) {
                    res.add(i);
                }
            }
        }
        return res;
    }


}
